from rest_framework import serializers


class RegisterSMSAPIVIewSerializer(serializers.Serializer):

    image_code_id = serializers.UUIDField(required=True,label='uuid')
    text = serializers.CharField(required=True,min_length=4,max_length=4,label='图片验证码')

    def validate(self, attrs):
        text = attrs.get('text')
        image_code_id = attrs.get('image_code_id')
        from django_redis import get_redis_connection
        redis_conn = get_redis_connection('code')

        redis_text = redis_conn.get('image_%s'%image_code_id)

        if redis_text.decode().upper() != text.upper():
            raise serializers.ValidationError('图片验证码输入有误')

        return attrs




